package view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

import model.IModel;

import com.jme3.input.InputManager;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

import controller.IController;
import eventManager.IEventData;

/*
 * Interface for specific object views 
 */
public abstract class AbstractView implements IView, ActionListener, AnalogListener {
	
	//protected Geometry geometry;
	protected Spatial spatial;
	
	protected HashSet<String> inputListeners = new HashSet<String>();	
	protected ArrayList<Control> JMEControls = new ArrayList<Control>();
	
	protected IController controller;
	protected IModel model;
	protected EViewList name; //Label for the view (i.e. "DEFAULT," "MILITARY," etc.)
	
	public AbstractView(EViewList name) {
		this.name = name;
	}
	
	public AbstractView(IController controller, IModel model)
	{
		this.model = model;
		this.controller = controller; 
	}
	
	//update view
	//public abstract void update();	
	
	//code necessary to initialize the view
	//public abstract void initView();
	
	//destroy view
	//public abstract void closeView();
	
	//load listeners specific to this object
	public abstract void registerInputListeners(InputManager inputManager);
	
	public abstract void onAction(String arg0, boolean arg1, float arg2);
	
	public abstract void onAnalog(String name, float value, float tpf);
	
	public Spatial getSpatial() {
		return this.spatial;
	}
	
	public void setSpatial(Spatial spatial) {
		this.spatial = spatial;
	}
	
	
//	public Geometry getGeometry() {
//		return this.geometry;
//	}	
	
	public HashSet<String> getInputListeners() {
		return this.inputListeners;
	}
	
	public void executeStrategy(IEventData event)
	{
		//Sends event notification to the controller, to act upon
		controller.handleEvent(event);
	}
	
	public void setController(IController controller) {
		this.controller = controller;
	}
	
	public void setModel(IModel model) {
		this.model = model;		
	}
	
	public EViewList getName() {
		return this.name;
	}
	
	public IModel getModel() {
		return this.model;
	}
	
	public void registerJMEControl(Control control, boolean enabled) {
		this.JMEControls.add(control);	
		//this.spatial.addControl(control);
		this.spatial.getControl(control.getClass()).setEnabled(enabled);
	}
	
	public void enableJMEControl(Class control) {
		this.spatial.getControl(control).setEnabled(true);
	}
	
	public void disableJMEControl(Class control) {
		this.spatial.getControl(control).setEnabled(false);
	}
	
	public ArrayList<Control> getJMEControls() {
		return this.JMEControls;
	}
	
}
